<?php
/**
*   常见问题
*/
namespace app\api\model;
use think\Model;
use app\common\model\OssUp;

class Upload extends Model
{
    /**
    * 上传文件
    * @param variable string 上传的变量
    * @param dir string 存储的目录
    */
    public function _uploadFile($variable='image', $dir = "other/image"){
        if(empty($_FILES)){
            $this->error = '请上传图片';
            return false;
        }
        if($_FILES[$variable]['error'] === 0){
            $file = $_FILES[$variable];
            $type = array_reverse(explode('.', $file['name']));
            $type = $type[0];
            $ob = new OssUp();
            $res = $ob->oss_up($file, $dir, $type);
            if($res){
               return $res;
            }else{
                $this->error = '图片上传失败';
                return false;
            }
        }else{
            $this->error = '图片上传失败';
            return false;
        }
    }

}